﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class Inventory : MonoBehaviour 
{
	public List<InventorySlot> slots;
	void Awake()
	{
		Sort ();
	}
	void Sort()
	{
		slots = slots.OrderBy (s => s.number).ToList ();
	}
	public void Add(Item item)
	{	
		Sort ();
		for (int i = 0; i < slots.Count; i++)
		{
			if (slots [i].item == null)
			{
				slots [i].Add (item);
				return;
			}
			Debug.Log ("inventory is full");
		}
	}
	public void DropAll()
	{
		foreach (InventorySlot slot in slots)
		{
			slot.Drop();
		}
	}
	public void SetLocalPlayer(Transform player)
	{	
		foreach (InventorySlot slot in slots)
		{
			slot.player = player;
		}
	}
}
